package com.yamanyar.weebill.dao.impl.jpa;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.yamanyar.weebill.dao.UserDAO;
import com.yamanyar.weebill.domain.User;

/**
 * JPA implementation of <code>UserDAO</code>.
 * 
 * Created in Jun 29, 2008.
 * 
 * @author Kaan Yamanyar
 */
@Repository
public class UserDAOImpl extends GenericDAOImpl<User, Long> implements UserDAO {

	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
	public List<User> findByFirstName(String firstName) {
		Query query = entityManager
				.createQuery("Select u from User u where u.firstName = ?1");
		query.setParameter(1, firstName);

		return query.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
	public List<User> findByMail(String mail) {
		Query query = entityManager
				.createQuery("Select u from User u where u.email = ?1");
		query.setParameter(1, mail);

		return query.getResultList();
	}

}
